package com.mapper;

import com.entity.TArticle;
import com.entity.TArticleExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface TArticleMapper {
    @SelectProvider(type=TArticleSqlProvider.class, method="countByExample")
    int countByExample(TArticleExample example);

    @DeleteProvider(type=TArticleSqlProvider.class, method="deleteByExample")
    int deleteByExample(TArticleExample example);

    @Delete({
        "delete from t_article",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into t_article (aid, uid, ",
        "url, title, author_nick, ",
        "read_amount, comment_amount, ",
        "create_time, update_time)",
        "values (#{aid,jdbcType=VARCHAR}, #{uid,jdbcType=INTEGER}, ",
        "#{url,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{authorNick,jdbcType=VARCHAR}, ",
        "#{readAmount,jdbcType=INTEGER}, #{commentAmount,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(TArticle record);

    @InsertProvider(type=TArticleSqlProvider.class, method="insertSelective")
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insertSelective(TArticle record);

    @SelectProvider(type=TArticleSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="aid", property="aid", jdbcType=JdbcType.VARCHAR),
        @Result(column="uid", property="uid", jdbcType=JdbcType.INTEGER),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="author_nick", property="authorNick", jdbcType=JdbcType.VARCHAR),
        @Result(column="read_amount", property="readAmount", jdbcType=JdbcType.INTEGER),
        @Result(column="comment_amount", property="commentAmount", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<TArticle> selectByExample(TArticleExample example);

    @Select({
        "select",
        "id, aid, uid, url, title, author_nick, read_amount, comment_amount, create_time, ",
        "update_time",
        "from t_article",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="aid", property="aid", jdbcType=JdbcType.VARCHAR),
        @Result(column="uid", property="uid", jdbcType=JdbcType.INTEGER),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="author_nick", property="authorNick", jdbcType=JdbcType.VARCHAR),
        @Result(column="read_amount", property="readAmount", jdbcType=JdbcType.INTEGER),
        @Result(column="comment_amount", property="commentAmount", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    TArticle selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, aid, uid, url, title, author_nick, read_amount, comment_amount, create_time, ",
            "update_time",
            "from t_article",
            "limit #{page,jdbcType=INTEGER},#{pageSize,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="aid", property="aid", jdbcType=JdbcType.VARCHAR),
            @Result(column="uid", property="uid", jdbcType=JdbcType.INTEGER),
            @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
            @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
            @Result(column="author_nick", property="authorNick", jdbcType=JdbcType.VARCHAR),
            @Result(column="read_amount", property="readAmount", jdbcType=JdbcType.INTEGER),
            @Result(column="comment_amount", property="commentAmount", jdbcType=JdbcType.INTEGER),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<TArticle> selectByPage(@Param("page")Integer page,@Param("pageSize") Integer pageSize);

    @UpdateProvider(type=TArticleSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TArticle record, @Param("example") TArticleExample example);

    @UpdateProvider(type=TArticleSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") TArticle record, @Param("example") TArticleExample example);

    @UpdateProvider(type=TArticleSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TArticle record);

    @Update({
        "update t_article",
        "set aid = #{aid,jdbcType=VARCHAR},",
          "uid = #{uid,jdbcType=INTEGER},",
          "url = #{url,jdbcType=VARCHAR},",
          "title = #{title,jdbcType=VARCHAR},",
          "author_nick = #{authorNick,jdbcType=VARCHAR},",
          "read_amount = #{readAmount,jdbcType=INTEGER},",
          "comment_amount = #{commentAmount,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(TArticle record);

    @Select({
            "select",
            "id, aid, uid, url, title, author_nick, read_amount, comment_amount, create_time, ",
            "update_time",
            "from t_article",
            "order by id desc limit 1"
    })
    TArticle selectNewest();
}